home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / RadioButtonPanel.java < prev    next >
Text File  |  1998-06-30  |  10KB  |  309 lines

  1. /*
  2.  * @(#)RadioButtonPanel.java    1.7 98/03/18
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. import com.sun.java.swing.*;
  22. import com.sun.java.swing.text.*;
  23. import com.sun.java.swing.border.*;
  24.  
  25. import java.awt.*;
  26. import java.awt.event.*;
  27. import java.util.*;
  28.  
  29.  
  30. /**
  31.  * RadioButtons!
  32.  *
  33.  * @version 1.7 03/18/98
  34.  * @author Jeff Dinkins
  35.  */
  36. public class RadioButtonPanel extends JPanel 
  37. {
  38.     // The Frame
  39.     SwingSet swing;
  40.  
  41.     ImageIcon radio = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/radio.gif","Grey circle with blue triangle inside");
  42.     ImageIcon radioSelected = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/radioSelected.gif","Grey circle with green triangle inside");
  43.     ImageIcon radioPressed = SwingSet.sharedInstance().loadImageIcon("images/WebSpice/radioPressed.gif","Grey circle with purple triangle inside");
  44.  
  45.     public RadioButtonPanel(SwingSet swing) {
  46.     this.swing = swing;
  47.  
  48.     ButtonGroup group;
  49.  
  50.     setBorder(swing.emptyBorder5);
  51.     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  52.  
  53.     // *************** radio buttons ****************
  54.     // text buttons
  55.     JPanel textButtons = SwingSet.createHorizontalPanel(false);
  56.     textButtons.setAlignmentX(LEFT_ALIGNMENT);
  57.     Border buttonBorder = new TitledBorder(null, "Text RadioButtons", 
  58.                            TitledBorder.LEFT, TitledBorder.TOP,
  59.                            swing.boldFont);
  60.  
  61.     Border emptyBorder = new EmptyBorder(5,5,5,5);
  62.     Border compoundBorder = new CompoundBorder( buttonBorder, emptyBorder);
  63.     textButtons.setBorder(compoundBorder);
  64.  
  65.     group = new ButtonGroup();
  66.     JRadioButton button;
  67.     button = new JRadioButton("One", true);
  68.     button.setToolTipText("This is a RadioButton with Text");
  69.     group.add(button);
  70.         button.setMnemonic('o');
  71.     swing.radioButtons.addElement(button);
  72.     textButtons.add(button);
  73.     textButtons.add(Box.createRigidArea(swing.hpad10));
  74.     
  75.     button = new JRadioButton("Two");
  76.     group.add(button);
  77.         button.setMnemonic('t');
  78.     button.setToolTipText("This is a RadioButton with Text");
  79.     swing.radioButtons.addElement(button);
  80.     textButtons.add(button);
  81.     textButtons.add(Box.createRigidArea(swing.hpad10));
  82.  
  83.     button = new JRadioButton("Three");
  84.     group.add(button);
  85.         button.setMnemonic('h');
  86.     button.setToolTipText("This is a RadioButton with Text");
  87.     swing.radioButtons.addElement(button);
  88.     textButtons.add(button);
  89.  
  90.  
  91.     // image buttons
  92.     group = new ButtonGroup();
  93.  
  94.     JPanel imageButtons = SwingSet.createHorizontalPanel(false);
  95.     imageButtons.setAlignmentX(LEFT_ALIGNMENT);
  96.     buttonBorder = new TitledBorder(null, "Image RadioButtons", 
  97.                            TitledBorder.LEFT, TitledBorder.TOP,
  98.                            swing.boldFont);
  99.     compoundBorder = new CompoundBorder(buttonBorder, emptyBorder);
  100.     imageButtons.setBorder(compoundBorder);
  101.  
  102.     // 1 image
  103.     button = new JRadioButton(swing.duke2);
  104.     group.add(button);
  105.     button.setSelectedIcon(swing.dukeWave);
  106.     button.setPressedIcon(swing.dukeWaveRed);
  107.     button.setRolloverIcon(swing.dukeWaveRed);
  108.     button.setSelected(true);
  109.     button.setToolTipText("This is a RadioButton with a Icon");
  110.     button.getAccessibleContext().setAccessibleName("Duke as a radio button");
  111.     swing.radioButtons.addElement(button);
  112.     imageButtons.add(button);
  113.     imageButtons.add(Box.createRigidArea(swing.hpad10));
  114.     
  115.     // 2 images
  116.     button = new JRadioButton(swing.duke2);
  117.     group.add(button);
  118.     swing.radioButtons.addElement(button);
  119.     button.setSelectedIcon(swing.dukeWave);
  120.     button.setPressedIcon(swing.dukeWaveRed);
  121.     button.setRolloverIcon(swing.dukeWaveRed);
  122.     button.setToolTipText("This is a RadioButton with a Icon");
  123.     button.getAccessibleContext().setAccessibleName("Duke as a radio button");
  124.     imageButtons.add(button);
  125.     imageButtons.add(Box.createRigidArea(swing.hpad10));
  126.  
  127.     // 3 images
  128.     button = new JRadioButton(swing.duke2);
  129.     group.add(button);
  130.     button.setSelectedIcon(swing.dukeWave);
  131.     button.setPressedIcon(swing.dukeWaveRed);
  132.     button.setRolloverIcon(swing.dukeWaveRed);
  133.     button.setToolTipText("This is a RadioButton with a Icon");
  134.     button.getAccessibleContext().setAccessibleName("Duke as a radio button");
  135.     swing.radioButtons.addElement(button);
  136.     imageButtons.add(button);
  137.  
  138.     // text&image buttons
  139.     group = new ButtonGroup();
  140.  
  141.     JPanel tiButtons = SwingSet.createHorizontalPanel(false);
  142.     tiButtons.setAlignmentX(LEFT_ALIGNMENT);
  143.     buttonBorder = new TitledBorder(null, "Image & Text RadioButtons", 
  144.                            TitledBorder.LEFT, TitledBorder.TOP,
  145.                            swing.boldFont);
  146.     compoundBorder = new CompoundBorder(buttonBorder, emptyBorder);
  147.     tiButtons.setBorder(compoundBorder);
  148.  
  149.     button = new JRadioButton("Left", radio);
  150.     group.add(button);
  151.     button.setToolTipText("This is a RadioButton with a Icon and Text");
  152.     button.setSelected(true);
  153.     button.setSelectedIcon(radioSelected);
  154.     button.setPressedIcon(radioPressed);
  155.     swing.radioButtons.addElement(button);
  156.     tiButtons.add(button);
  157.     tiButtons.add(Box.createRigidArea(swing.hpad10));
  158.  
  159.     button = new JRadioButton("Center", radio);
  160.     group.add(button);
  161.     swing.radioButtons.addElement(button);
  162.     button.setToolTipText("This is a RadioButton with a Icon and Text");
  163.     button.setSelectedIcon(radioSelected);
  164.     button.setPressedIcon(radioPressed);
  165.     tiButtons.add(button);
  166.     tiButtons.add(Box.createRigidArea(swing.hpad10));
  167.  
  168.     button = new JRadioButton("Right", radio);
  169.     group.add(button);
  170.     swing.radioButtons.addElement(button);
  171.     button.setToolTipText("This is a RadioButton with a Icon and Text");
  172.     button.setSelectedIcon(radioSelected);
  173.     button.setPressedIcon(radioPressed);
  174.     tiButtons.add(button);
  175.     tiButtons.add(Box.createHorizontalBox());
  176.  
  177.     // Add button panels to buttonPanel
  178.     JPanel buttonPanel = SwingSet.createVerticalPanel(true);
  179.     buttonPanel.setAlignmentX(LEFT_ALIGNMENT);
  180.     buttonPanel.setAlignmentY(TOP_ALIGNMENT);
  181.  
  182.     buttonPanel.add(textButtons);
  183.  
  184.     buttonPanel.add(Box.createVerticalStrut(10));
  185.  
  186.  
  187.     buttonPanel.add(imageButtons);
  188.  
  189.     buttonPanel.add(Box.createVerticalStrut(10));
  190.  
  191.     buttonPanel.add(tiButtons);
  192.     buttonPanel.add(tiButtons);
  193.     buttonPanel.add(Box.createGlue());
  194.  
  195.  
  196.     // *************** Create the button controls ****************
  197.     JPanel controls = new JPanel() {
  198.         public Dimension getMaximumSize() {
  199.         return new Dimension(300, super.getMaximumSize().height);
  200.         }
  201.     };
  202.     controls.setLayout(new BoxLayout(controls, BoxLayout.Y_AXIS));
  203.     controls.setAlignmentY(TOP_ALIGNMENT);
  204.     controls.setAlignmentX(LEFT_ALIGNMENT);
  205.  
  206.     JPanel buttonControls = SwingSet.createHorizontalPanel(true);
  207.     buttonControls.setAlignmentY(TOP_ALIGNMENT);
  208.     buttonControls.setAlignmentX(LEFT_ALIGNMENT);
  209.  
  210.     JPanel leftColumn = SwingSet.createVerticalPanel(false);
  211.     leftColumn.setAlignmentX(LEFT_ALIGNMENT);
  212.     leftColumn.setAlignmentY(TOP_ALIGNMENT);
  213.  
  214.     JPanel rightColumn = SwingSet.createVerticalPanel(false);
  215.     rightColumn.setAlignmentX(LEFT_ALIGNMENT);
  216.     rightColumn.setAlignmentY(TOP_ALIGNMENT);
  217.  
  218.     buttonControls.add(leftColumn);
  219.     buttonControls.add(Box.createRigidArea(swing.hpad20));
  220.     buttonControls.add(rightColumn);
  221.     buttonControls.add(Box.createRigidArea(swing.hpad20));
  222.  
  223.     controls.add(buttonControls);
  224.  
  225.     // Display Options
  226.     JLabel l = new JLabel("Display Options:");
  227.     leftColumn.add(l);
  228.     l.setFont(swing.boldFont);
  229.  
  230.      JCheckBox bordered = new JCheckBox("Paint Border");
  231.     bordered.setToolTipText("Click here to turn border painting on or off.");
  232.         bordered.setMnemonic('b');
  233.      bordered.addItemListener(swing.buttonDisplayListener);
  234.      leftColumn.add(bordered);
  235.  
  236.      JCheckBox focused = new JCheckBox("Paint Focus");
  237.     focused.setToolTipText("Click here to turn focus painting on or off.");
  238.         focused.setMnemonic('f');
  239.      focused.setSelected(true);
  240.      focused.addItemListener(swing.buttonDisplayListener);
  241.      leftColumn.add(focused);
  242.  
  243.     JCheckBox enabled = new JCheckBox("Enabled");
  244.     enabled.setSelected(true);
  245.     enabled.setToolTipText("Click here to enable or disable the radio buttons.");
  246.         enabled.setMnemonic('e');
  247.     enabled.addItemListener(swing.buttonDisplayListener);
  248.     leftColumn.add(enabled);
  249.  
  250.  
  251.     leftColumn.add(Box.createRigidArea(swing.vpad20));
  252.  
  253.     
  254.     l = new JLabel("Pad Amount:");
  255.     leftColumn.add(l);
  256.     l.setFont(swing.boldFont);
  257.     
  258.     group = new ButtonGroup();
  259.     JRadioButton defaultPad = new JRadioButton("Default");
  260.         defaultPad.setMnemonic('d');
  261.     defaultPad.setToolTipText("Uses the default padding between the border and label.");
  262.     group.add(defaultPad);
  263.     defaultPad.setSelected(true);
  264.      defaultPad.addItemListener(swing.buttonPadListener);
  265.     leftColumn.add(defaultPad);
  266.  
  267.     JRadioButton zeroPad = new JRadioButton("0");
  268.         zeroPad.setMnemonic('0');
  269.     group.add(zeroPad);
  270.     zeroPad.setToolTipText("Uses no padding between the border and label.");
  271.      zeroPad.addItemListener(swing.buttonPadListener);
  272.     leftColumn.add(zeroPad);
  273.  
  274.     JRadioButton tenPad = new JRadioButton("10");
  275.         tenPad.setMnemonic('1');
  276.     tenPad.setToolTipText("Uses a 10 pixel pad between the border and label.");
  277.     group.add(tenPad);
  278.      tenPad.addItemListener(swing.buttonPadListener);
  279.     leftColumn.add(tenPad);
  280.     
  281.     leftColumn.add(Box.createRigidArea(swing.vpad20));
  282.  
  283.     // *************** Create the layout controls ****************
  284.     // Create Text Position Layout control
  285.     JPanel textPosition = DirectionButton.createDirectionPanel(true, "E", swing.textPositionListener);
  286.     JPanel labelAlignment = DirectionButton.createDirectionPanel(true, "C", swing.labelAlignmentListener);
  287.  
  288.     l = new JLabel("Text Position:");
  289.     rightColumn.add(l);
  290.     l.setFont(swing.boldFont);
  291.      rightColumn.add(textPosition);
  292.  
  293.      rightColumn.add(Box.createRigidArea(swing.vpad20));
  294.  
  295.     l = new JLabel("Content Alignment:");
  296.     rightColumn.add(l);
  297.     l.setFont(swing.boldFont);
  298.      rightColumn.add(labelAlignment);
  299.  
  300.      rightColumn.add(Box.createGlue());
  301.  
  302.     add(buttonPanel);
  303.     add(Box.createRigidArea(swing.hpad10));
  304.      add(controls);
  305.     }
  306.  
  307.     
  308. }
  309.